﻿package export.hero
{
    import base.BaseSummon;
    
    import com.game.data.constant.FrameRate;
    import com.game.manager.AnimationManager;
    import com.game.manager.SoundManager;
    
    import export.bullet.RegionBullet;
    
    import flash.geom.Point;
    
    import flash.geom.Rectangle;
    
    public class Role1Shadow extends BaseSummon
    {
        
        private var _ratio:int = 1;
        
        public function Role1Shadow()
        {
            super();
            setDestroyInCount(FrameRate.ANIMATE_FRAME_RATE * 3);
            setAction("idle");
            setInvincible(9999);
        }
        
        override protected function initBBDC():void
        {
            var showInfo:Object = {
                weapon: 1,
                cloth: 1,
                wing: 1
            };
            bbdc = AnimationManager.getAnimation("Role1Action", showInfo);
            bbdc.setOffset(-35, 0);
            bbdc.setAction("idle");
            bbdc.turnRight();
            bbdc.addCallBack(onEnterFrame, onActionOver);
            bodyContainer.addChild(bbdc);
        }
        
        override protected function initCollideArea():void
        {
            collideBox = new Rectangle(-30, -100, 60, 103);
            super.initCollideArea();
        }
        
        override public function setAction(action:String):void
        {
            switch (action)
            {
                case "hurt":
                    action = "idle";
                    bbdc.play();
                    break;
                case "skill4":
                    alpha = 0.5;
                    setLostGravity();
                    velocity.setZero();
                    break;
                    //身外身
                case "skill7":
                    //定海神针
                case "skill6":
                    //火魔斩
                    bbdc.play();
                    resetGravity();
                    alpha = 1;
                    break;
                default:
                    return;
            }
            bbdc.setAction(action);
        }
        
        override protected function onEnterFrame(action:String, frameCount:int):void
        {
            var b:RegionBullet;
            switch (action)
            {
                case "skill6":
                    //火魔斩
                    setDestroyInCount(2);
                    if (frameCount == 1)
                    {
                        b = new RegionBullet();
                        b.setCollideArea(-237, -325.05, 474 * bbdc.getDirect(), 325.05);
                        b.setDestroyInCount(27);
                        b.setOwner(this);
                        b.setAction("Role1Skill6_1");
                        b.hitVO.addProtection = 0;
                        b.hitVO.addEnergyMax = 0;
                        b.setDirect(bbdc.getDirect());
                        b.setHurt(getActionHurt("skill6_1"));
                    }
                    if (frameCount == 34)
                    {
                        SoundManager.playSound("Role1_skill6_2");
                        b = new RegionBullet();
                        b.setCollideArea(-109, -325.05, 218 * bbdc.getDirect(), 325.05);
                        b.setDestroyInCount(bbdc.frameLeft);
                        b.setOwner(this);
                        b.setAction("Role1Skill6_2");
                        b.hitVO.addProtection = 0;
                        b.hitVO.addEnergyMax = 0;
                        b.setDirect(bbdc.getDirect());
                        b.setHurt(getActionHurt("skill6_2"));
                    }
                    break;
                case "skill7" :
                    //定海神针
                    setDestroyInCount(2);
                    if (frameCount == 8)
                    {
                        b = new RegionBullet();
                        b.setCollideArea(-112, -351.05, 223 * bbdc.getDirect(), 351.05);
                        b.setDestroyInCount(bbdc.frameLeft);
                        b.setOwner(this);
                        b.setAction("Role1Skill7");
                        b.hitVO.addProtection = 0;
                        b.hitVO.addEnergyMax = 0;
                        b.setDirect(bbdc.getDirect());
                        b.setHurt(getActionHurt("skill7"));
                    }
                    break;
            }
            if (b)
            {
                gc.gameScene.addChild(b);
                magicBulletArray.push(b);
            }
        }
        
        override protected function onActionOver(action:String):void
        {
            switch (action)
            {
                case "idle":
                    setAction("idle");
                    break;
                default:
                    destroy();
            }
        }
        
        /**
         * 传入符合条件怪物的个数
         * @param value
         */
        public function setHurtRatio(value:int):void
        {
            _ratio = value;
        }
        
        override public function getActionHurt(action:String):int
        {
            //ratio最低为1，因此0.4为最低倍率
            var hurtAdd:Number = 0.3;
            hurtAdd += 0.1 * _ratio;
            return _owner.getActionHurt(action) * (hurtAdd > 1 ? 1 : hurtAdd);
        }
    }
}
